package com.dhb.pattern.singleton.threadlocal;

/**
 * 功能描述：ThreadLocal 不能保证其创建的对象是全局唯一，
 *          但是能保证在单个线程中是唯一的，天生的线程安全。
 * 创建人：citymoon
 * 创建日期：2019/5/4
 */
public class ThreadLocalSingleton {
    private static final ThreadLocal<ThreadLocalSingleton> threadLocalInstance =
            new ThreadLocal<ThreadLocalSingleton>(){
                @Override
                protected ThreadLocalSingleton initialValue() {
                    return new ThreadLocalSingleton();
                }
            };

    private ThreadLocalSingleton(){}

    public static ThreadLocalSingleton getInstance(){
        return threadLocalInstance.get();
    }
}
